const cheerio = require('cheerio')

function whatHotParser (body) {
  var $ = cheerio.load(body)
  let galleryArray = []
  try {
    if ($('#pp').html() === null) {
      throw new Error('WHATSHOTPARSEERROR')
    }
    $('#pp').find('.id2 a').each(function (i, elem) {
      let gid = $(this).attr('href').split('/')[4]
      let token = $(this).attr('href').split('/')[5]
      galleryArray.push([Number(gid), token])
    })
    return galleryArray
  } catch (err) {
    throw new Error(err.message)
  }
}

module.exports = whatHotParser
